<?php

use Yaf\Registry;

class ErrorController extends ApiBaseController
{
    public function errorAction(\Exception $exception) {
        $err_no = $exception->getCode();
        $err_msg = $exception->getMessage();

        Registry::get('notify_log')->err('错误: ' . $err_msg . '[file: ' . $exception->getFile() . ', line: ' . $exception->getLine() . ']');

        switch ($err_no) {
            case '400':
                header('HTTP/1.1 400 INVALID REQUEST', true, $err_no);
                break;
            case '403':
                header('HTTP/1.1 403 Forbidden', true, 401);
                break;
            case '404':
                header('HTTP/1.1 404 NOT FOUND', true, $err_no);
                break;
            case '422':
                header('HTTP/1.1 422 Unprocesable entity', true, $err_no);
                break;
            case '410':
                header('HTTP/1.1 410 Gone', true, $err_no);
                break;
            default:
                header('HTTP/1.1 401 Unauthorized', true, 401);
                break;
        }

        return $this->_responseString('error');
//        return $this->_responseJson($result, $err_no, $err_msg);

    }

}
